var ns;
app = new Vue({
    el: '#app',
    data: {
        form: {
            LeaveTime: ''
        },
        itemform: {},
        status:1,
        ID: 0,
        imglist:[],
    },
    methods: {
        get_data: function() {
            var that = this;
            var options = {};
            options.action = "getvisitdetaildata";
            options.ID = that.ID;
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.status = data.status;
                    that.ID = data.ID;
                    if (that.status == 1) {
                        that.form = data.formdata;
                    } else {
                        that.itemform = data.formdata;
                    }
                    that.imglist = data.formdata.imgslist;
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        do_leave: function() {
            var that = this;
            api.confirm({
                title: '提示',
                msg: '是否确认离开？',
                buttons: ['确认', '取消']
            }, function(ret, err) {
                if (ret.buttonIndex == 1) {
                    var options = {};
                    options.action = "dosavevisitleave";
                    options.ID = that.ID;
                    ns.post(options, function(succeed, data, err) {
                        if (succeed) {
                            api.toast({
                                msg: '操作成功',
                                duration: 2000,
                                location: 'bottom'
                            });
                            setTimeout(function() {
                                api.closeWin();
                            }, 500)
                        } else if (err) {
                            api.toast({
                                msg: err,
                                duration: 2000,
                                location: 'bottom'
                            });
                        }
                    });
                }
            });
        },
        do_viewimages: function (activeIndex) {
            var that = this;
            var imageUrls = [];
            for (var i = 0; i < that.imglist.length; i++) {
                imageUrls.push(that.imglist[i].url);
            }
            var imageBrowser = api.require('imageBrowser');
            imageBrowser.openImages({
                showList: false,
                activeIndex: activeIndex,
                imageUrls: imageUrls
            });
        },
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.ID = api.pageParam.id || 0;
    setTimeout(function() {
        app.get_data();
    }, 500)
};
